package com.fulinlin;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Set;

/**
 * 页面请求接口
 *
 * @author Dong_Jia_Qi on 2022/1/15
 */
@RestController
@Slf4j
public class Controller {
    @Autowired
    GetNewestGithubDns getNewestGithubDns;
    @Autowired
    RedisUtil redisUtil;
    @RequestMapping("getDns")
    public Set<Object> getDns(){
        log.info("进来 getDns 方法");
        return getNewestGithubDns.getDnsByRedis();
    }
    @RequestMapping("getDnsForce")
    public Set<GithubDns> getDnsForce(){
        log.info("进来 getDnsForce 方法");
        try {
            Set<GithubDns> githubDns = getNewestGithubDns.getGithubDns();
            getNewestGithubDns.updateGitRedis(githubDns);
            return githubDns;
        } catch (IOException e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }
    @RequestMapping("everyDay")
    public String everyDay(){
        log.info("进来 everyDay 方法");
        boolean b = getNewestGithubDns.writeGithubDnsHosts();
        return String.valueOf(b);
    }
    @RequestMapping("getUpdateDate")
    public String getUpdateDate(){
        log.info("进来 getUpdateDate 方法");
        return getNewestGithubDns.getUpdateDate();
    }

}
